package com.hefei.garden.config.redis;

import com.alibaba.cloud.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * @author devil
 */
@RefreshScope
@Configuration
public class JedisConfig {

    @Value(value = "${spring.redis.host}")
    private String host;

    @Value(value = "${spring.redis.port}")
    private int port;

    @Value(value = "${spring.redis.password}")
    private String password;

    @Value(value = "${spring.redis.timeout}")
    private int timeout;

    @Bean
    @RefreshScope
    public JedisPool jedisPool() {
        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
        return new JedisPool(
                jedisPoolConfig,
                host,
                port,
                timeout,
                StringUtils.isBlank(password) ? null : password
        );
    }

}